<?php
//======================================================================================
//
// Function: Save a type
//
// Programmer: JKJ
// Date : 2020-11-10
//
// Copyright Reeft A/S (c) - 2020
//======================================================================================
//======================================================================================
// General config
//======================================================================================
include "config/config.php";
include "include/REEFT_date_convert.php";
//======================================================================================
// Get input
//======================================================================================
if (isset($_REQUEST["mode"])) $mode = $_REQUEST["mode"];
else $mode = '';
if (isset($_REQUEST["data"])) {
$data = $_REQUEST["data"];
} else {
$data = 'hovsa';
}
if ( $mode == '' ) {
echo "There's no action....1";
exit;
}
if ( $mode <> '*add' and $mode <> '*update' ) {
echo "There's no action....2";
exit;
}
if ( $data == 'hovsa' ) {
echo "There's no data....";
exit;
}
//======================================================================================
// Convert from JSON
//======================================================================================
// Just in case
$typeValue = '';
$fk_country = 0;
$json = json_decode($data);
foreach($json as $obj){
$key = $obj->name;
$value = $obj->value;
if ( $key == 'modal-input-pk_type') {
$pk_type = $value;
}
if ( $key == 'modal-input-typeCode') {
$typeCode = $value;
}
if ( $key == 'modal-input-typeValue') {
$typeValue = $value;
}
if ( $key == 'modal-input-typeName') {
$typeName = $value;
}
if ( $key == 'modal-input-active') {
$active = $value;
}
if ( $key == 'modal-input-timestamp') {
$timestamp = $value;
}
if ( $key == 'modal-input-minValueData') {
$minValueData = $value;
}
if ( $key == 'modal-input-minValueColor') {
$minValueColor = $value;
}
if ( $key == 'modal-input-lineChartColor') {
$lineChartColor = $value;
}
if ( $key == 'modal-input-lineChartThickness') {
$lineChartThickness = $value;
}
if ( $key == 'modal-input-normalValueColor') {
$normalValueColor = $value;
}
if ( $key == 'modal-input-lineChartColor') {
$lineChartColor = $value;
}
if ( $key == 'modal-input-maxValueData') {
$maxValueData = $value;
}
if ( $key == 'modal-input-maxValueColor') {
$maxValueColor = $value;
}
if ( $key == 'modal-input-type_pair_code') {
$type_pair_code = $value;
}
if ( $key == 'modal-input-fk_country') {
$fk_country = $value;
}
}
//======================================================================================
// Get session variables
//======================================================================================
include "include/getsession.php";
//======================================================================================
// Set language
//======================================================================================
include "include/set_language.php";
//======================================================================================
// Connect to SQLite database in file
//======================================================================================
header('Content-Type: text/xml; charset=UTF-8');
$currentDate = date('Y-m-d');
$currentTime = date('H:i:s');
$xmlString = "<?xml version=\"1.0\"?>\n";
$xmlString .= "<data>\n";
//======================================================================================
// Connect to some DB
//======================================================================================
include "include/db_connect.php";
//======================================================================================
// Set active, token and other default values
//======================================================================================
if ( $timestamp == '' ) {
$timestamp = REEFT_current_utc();
}
//======================================================================================
// Check typeCode
//======================================================================================
if ( $typeCode == '' ) {
$typeCode = '*NONE';
}
//======================================================================================
// Create SQL
//======================================================================================
if ( $mode == '*update')
{
// $sql = "update visual_types
// set
// typeCode = '$typeCode',
// typeValue = '$typeValue',
// typeName = '$typeName',
// active = '$active',
// minValueData = '$minValueData',
// maxValueData = '$maxValueData',
// minValueColor = '$minValueColor',
// maxValueColor = '$maxValueColor',
// normalValueColor = '$normalValueColor',
// lineChartColor = '$lineChartColor',
// lineChartThickness = '$lineChartThickness',
// type_pair_code = '$type_pair_code',
// fk_country = '$fk_country'
// where pk_type = $pk_type
// ";
$sql = "update reeft_customer
cust_active '$cust_active',
cust_number '$cust_number',
cust_name '$cust_name',
cust_group '$cust_group',
product '$product',
description '$description',
integration_version '$integration_version',
fileformat_ext_file '$fileformat_ext_file',
fileformat_exportterminationfile '$fileformat_exportterminationfile',
fileformat_numberdecimalseparator '$fileformat_numberdecimalseparator',
fileformat_separator '$fileformat_separator',
fileformat_codepage '$fileformat_codepage',
program_dir '$program_dir',
input_dir '$input_dir',
output_dir '$output_dir',
error_dir '$error_dir',
done_dir '$done_dir',
log_dir '$log_dir',
import_functions '$import_functions',
export_functions '$export_functions',
client_id '$client_id',
client_secret '$client_secret',
organizationId '$organizationId',
create_user '$create_user',
create_timestamp '$create_timestamp',
update_user '$update_user',
update_timestamp '$update_timestamp',
company_logo_url '$company_logo_url',
number_of_exports '$number_of_exports',
number_of_imports '$number_of_imports',
ERPname '$ERPname',
ERPdescription '$ERPdescription',
ERPurl '$ERPurl',
json_default_path '$json_default_path',
json_gps_default_path '$json_gps_default_path',
name '$name',
group '$group'
";
}
if ( $mode == '*add')
{
$sql = "INSERT INTO reeft_customer
(
cust_active,
cust_number,
cust_name,
cust_group,
product,
description,
integration_version,
fileformat_ext_file,
fileformat_exportterminationfile,
fileformat_numberdecimalseparator,
fileformat_separator,
fileformat_codepage,
program_dir,
input_dir,
output_dir,
error_dir,
done_dir,
log_dir,
import_functions,
export_functions,
client_id,
client_secret,
organizationId,
create_user,
create_timestamp,
update_user,
update_timestamp,
company_logo_url,
number_of_exports,
number_of_imports,
ERPname,
ERPdescription,
ERPurl,
json_default_path,
json_gps_default_path,
name,
group
)
VALUES
(
'$cust_active',
'$cust_number',
'$cust_name',
'$cust_group',
'$product',
'$description',
'$integration_version',
'$fileformat_ext_file',
'$fileformat_exportterminationfile',
'$fileformat_numberdecimalseparator',
'$fileformat_separator',
'$fileformat_codepage',
'$program_dir',
'$input_dir',
'$output_dir',
'$error_dir',
'$done_dir',
'$log_dir',
'$import_functions',
'$export_functions',
'$client_id',
'$client_secret',
'$organizationId',
'$create_user',
'$create_timestamp',
'$update_user',
'$update_timestamp',
'$company_logo_url',
'$number_of_exports',
'$number_of_imports',
'$ERPname',
'$ERPdescription',
'$ERPurl',
'$json_default_path',
'$json_gps_default_path',
'$name',
'$group'
)";
// $sql = "INSERT INTO
// visual_types
// (
// typeCode,
// typeValue,
// typeName,
// active,
// timestamp,
// minValueData,
// maxValueData,
// minValueColor,
// maxValueColor,
// normalValueColor,
// lineChartColor,
// lineChartThickness,
// type_pair_code,
// fk_country
// )
// VALUES
// (
// '$typeCode',
// '$typeValue',
// '$typeName',
// '$active',
// '$timestamp',
// " . ($minValueData ? "'$minValueData'" : 'NULL') . ",
// " . ($maxValueData ? "'$maxValueData'" : 'NULL') . ",
// '$minValueColor',
// '$maxValueColor',
// '$normalValueColor',
// '$lineChartColor',
// '$lineChartThickness',
// '$type_pair_code',
// " . ($fk_country ? "'$fk_country'" : 'NULL') . ",
// '$fk_country'
// )
// ";
}
//echo $sql;
//======================================================================================
// Get data
//======================================================================================
include "include/db_run_sql.php";
if ( $current_elm == 0 ) {
$returnCode = '99';
$returnMsg = 'No data found';
} else {
$returnCode = '00';
$returnMsg = 'Alles ist gut';
}
// Create header
$xmlString .= "\t<header>\n";
$xmlString .= "\t\t<mode>" . $mode . "</mode>\n";
$xmlString .= "\t\t<rows_updated>" . $current_elm . "</rows_updated>\n";
$xmlString .= "\t\t<currentDate>" . $currentDate . "</currentDate>\n";
$xmlString .= "\t\t<currentTime>" . $currentTime . "</currentTime>\n";
$xmlString .= "\t\t<returnCode>" . $returnCode . "</returnCode>\n";
$xmlString .= "\t\t<returnMsg>" . $returnMsg . "</returnMsg>\n";
$xmlString .= "\t</header>\n";
//======================================================================================
// Paint it black
//======================================================================================
$xmlString = $xmlString . "</data>\n";
echo $xmlString;
?>